home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / disasm.tar / disasm / instr1.c < prev    next >
C/C++ Source or Header  |  1990-04-25  |  2KB  |  136 lines

  1. #include "dis48.h"
  2.  
  3. char    *OpStr1[8] = {
  4.     "a, @d0", "a, @d1", "@d0, a", "@d1, a",
  5.     "c, @d0", "c, @d1", "@d0, c", "@d1, c"
  6. };
  7.  
  8. char *
  9. #ifdef ANSI
  10. Instr1(char *mem, NAddr *addr, char *out)
  11. #else
  12. Instr1(mem, addr, out)
  13. char    *mem;
  14. NAddr    *addr;
  15. char    *out;
  16. #endif
  17. {
  18.     Nybble    n;
  19.     Nybble    fn;
  20.     char    *p;
  21.     char    c;
  22.     
  23.     switch (n = GetNybble(mem, (*addr)++)) {
  24.     case 0:
  25.     case 1:
  26.         p = AppendStr(out, "move.w\t\t");
  27.         fn = GetNybble(mem, (*addr)++);
  28.         c = (fn < 8) ? 'a' : 'c';
  29.         fn = (fn & 7) + '0';
  30.         if (n == 0)
  31.             APPEND_CHAR(p, c);
  32.         else {
  33.             APPEND_CHAR(p, 'r');
  34.             APPEND_CHAR(p, fn);
  35.         }
  36.         
  37.         APPEND_COMMA(p);
  38.         if (n == 0) {
  39.             APPEND_CHAR(p, 'r');
  40.             APPEND_CHAR(p, fn);
  41.             
  42.         } else
  43.             APPEND_CHAR(p, c);
  44.         
  45.         break;
  46.         
  47.     case 2:
  48.         p = AppendStr(out, "swap.w\t\t");
  49.         n = GetNybble(mem, (*addr)++);
  50.         APPEND_CHAR(p, (n < 8) ? 'a' : 'c');
  51.         APPEND_COMMA(p);
  52.         APPEND_CHAR(p, 'r');
  53.         APPEND_BDIGIT(p, n & 7);
  54.         break;
  55.     
  56.     case 3:
  57.         n = GetNybble(mem, (*addr)++);
  58.         p = AppendStr(out, (n & 2) ? "swap" : "move");
  59.         APPEND_CHAR(p, '.');
  60.         APPEND_CHAR(p, (n < 8) ? 'a' : '4');
  61.         APPEND_TAB(p);
  62.         APPEND_TAB(p);
  63.         APPEND_CHAR(p, (n & 4) ? 'c' : 'a');
  64.         APPEND_COMMA(p);
  65.         APPEND_CHAR(p, 'd');
  66.         APPEND_BDIGIT(p, n & 1);
  67.         break;
  68.         
  69.     case 4:
  70.     case 5:
  71.         p = AppendStr(out, "move");
  72.         fn = GetNybble(mem, (*addr)++);
  73.         if (n == 4) {
  74.             APPEND_CHAR(p, '.');
  75.             APPEND_CHAR(p, (fn < 8) ? 'a' : 'b');
  76.             APPEND_TAB(p);
  77.         
  78.         } else {
  79.             n = GetNybble(mem, (*addr)++);
  80.             if (fn < 8)
  81.                 p = AppendField(p, n);
  82.                 
  83.             else {
  84.                 APPEND_CHAR(p, '.');
  85.                 p = Append16(p, n);
  86.                 APPEND_TAB(p);
  87.             }
  88.         }
  89.         
  90.         if ((p - out) < 8)
  91.             APPEND_TAB(p);
  92.             
  93.         p = AppendStr(p, OpStr1[fn & 7]);
  94.         break;
  95.     
  96.     case 6:
  97.     case 7:
  98.         p = AppendStr(out, "add.a\t\t");
  99.         APPEND_IMMMARK(p);
  100.         p = Append16(p, GetNybble(mem, (*addr)++));
  101.         APPEND_COMMA(p);
  102.         APPEND_CHAR(p, 'd');
  103.         APPEND_BDIGIT(p, n & 1);
  104.         break;
  105.         
  106.     default:
  107.         c = (n < 0xc) ? '0' : '1';
  108.         if ((n & 3) == 0) {
  109.             p = AppendStr(out, "sub.a\t\t");
  110.             APPEND_IMMMARK(p);
  111.             p = Append16(p, GetNybble(mem, (*addr)++));
  112.         
  113.         } else {
  114.             p = AppendStr(out, "move.");
  115.             switch (n & 3) {
  116.             case 1: n = 2; break;
  117.             case 2: n = 4; break;
  118.             case 3: n = 5; break;
  119.             }
  120.             
  121.             APPEND_BDIGIT(p, n);
  122.             APPEND_TAB(p);
  123.             APPEND_TAB(p);
  124.             p = AppendImmNyb(p, mem, addr, n);
  125.         }
  126.         
  127.         APPEND_COMMA(p);
  128.         APPEND_CHAR(p, 'd');
  129.         APPEND_CHAR(p, c);
  130.         break;
  131.     }
  132.     
  133.     TERMINATE(p);
  134.     return(p);
  135. }
  136.